# Scrapy settings for JDSpider project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'JDSpider'

SPIDER_MODULES = ['JDSpider.spiders']
NEWSPIDER_MODULE = 'JDSpider.spiders'

# 配置数据库信息
DB_HOST = 'localhost'
DB_PORT = 3306
DB_USER = 'root'
DB_PASS = '123456'
DB_NAME = 'spider'

# 设置用户代理
# USER_AGENT = 'JDSpider (+http://www.yourdomain.com)'

# 遵守 robots.txt 规则
ROBOTSTXT_OBEY = False

# 配置 Scrapy 执行的最大并发请求数 (默认值:16)
CONCURRENT_REQUESTS = 16

# 配置请求延迟 (默认值:0)
# DOWNLOAD_DELAY = 1
# RANDOMIZE_DOWNLOAD_DELAY = True

# 设置下载延迟选择其中一行命令：
# CONCURRENT_REQUESTS_PER_DOMAIN = 16
# CONCURRENT_REQUESTS_PER_IP = 16

# 禁用 cookies (默认启用)
# COOKIES_ENABLED = False

# 禁用 Telnet 远程登录控制台 (默认情况下启用)
# TELNETCONSOLE_ENABLED = False

# 重写默认请求头
# DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
# }

# 启用或禁用蜘蛛中间件
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#    'JDSpider.middlewares.JdspiderSpiderMiddleware': 543,
# }

# 启用或禁用下载器中间件
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
    'JDSpider.middlewares.JdspiderDownloaderMiddleware': 543,
}

# 启用或禁用扩展
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
# }

# 配置项目管道
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
    'JDSpider.pipelines.DbPipeLine': 200,
    'JDSpider.pipelines.ExcelPipeline': 300,
}

# Enable and configure the AutoThrottle extension (disabled by default)
# 启用并配置 AutoThrottle 节流算法扩展 (默认禁用)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# 初始下载延迟
# AUTOTHROTTLE_START_DELAY = 5
# 在高延迟情况下设置的最大下载延迟
# AUTOTHROTTLE_MAX_DELAY = 60
# Scrapy 并行发送到每个远程服务器的平均请求数
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# 启用显示收到的每个响应的限制统计信息 (默认开启)
# AUTOTHROTTLE_DEBUG = False

# 启用和配置 HTTP 缓存 (默认禁用)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = 'httpcache'
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
